/*
 * 文件名： VehicleLocationData.java
 * 
 * 创建日期： 2016年11月25日
 *
 * Copyright(C) 2016, by <a href="mailto:liws@xingyuanauto.com">liws</a>.
 *
 * 原始作者: liws
 *
 */
package com.moli.iov.protocol.model.realtime;

import java.io.Serializable;

import com.moli.iov.protocol.codec.DataEncoder;
import com.moli.iov.protocol.codec.Serialize;
import com.moli.iov.protocol.enums.realtime.LocationStateTag;
import com.moli.iov.protocol.model.EntityBytesLen;
import com.moli.iov.util.ByteArrayUtil;


/**
 * 车辆位置 数据
 *
 * @author <a href="mailto:liws@xingyuanauto.com">liws</a>
 *
 * @version $Revision$
 *
 * @since 2016年11月25日
 */
@Serialize(unit="byte",isBigEndian=true)
public class VehicleGpsReq implements Serializable,EntityBytesLen{
	
	public static final long serialVersionUID = 1L;
	

	 /**
	 *
	 */
	@Override
	public int getBytesLen() {
		return 9;
	}
	
	/**
	 * 车辆定位状态
	 * 按bit计算
	 * 0-bit -> 0:有效定位;1:无效定位
	 * 1-bit -> 0:北纬;1:南纬
	 * 2-bit -> 0:东经;1:西经
	 * 3-7bit ->保留
	 */
	@Serialize(unit="byte",offset=0,size=1)
	public LocationStateTag locationState;
	
	/**
	 * 经度
	 * 以度为单位乘以 10的6次方,精确到百万分之一
	 */
	@Serialize(unit="byte",offset=1,size=4,coefficient=0.000001,precision=6)
	public double longitude;
	
	/**
	 * 纬度
	 * 以度为单位乘以 10的6次方,精确到百万分之一
	 */
	@Serialize(unit="byte",offset=5,size=4,coefficient=0.000001,precision=6)
	public double latitude;

	public LocationStateTag getLocationState() {
		return locationState;
	}

	public void setLocationState(LocationStateTag locationState) {
		this.locationState = locationState;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}
	
	 /**
	 *
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("VehicleGpsReq [locationState=");
		builder.append(locationState);
		builder.append(", longitude=");
		builder.append(longitude);
		builder.append(", latitude=");
		builder.append(latitude);
		builder.append("]");
		return builder.toString();
	}

	public static void main(String[] args) {
		VehicleGpsReq vlData = new VehicleGpsReq();
		vlData.setLocationState(new LocationStateTag(LocationStateTag.IsValid.NO,LocationStateTag.LAT.SOUTH,LocationStateTag.LON.WEST));
		vlData.setLatitude(155778789);
		vlData.setLongitude(28987654);
		//v.setReserves(reserves);
		
//		ReportHeader rh = new ReportHeader();
//		rh.setCommandTag(CommandTag.VEHICLE_LOGIN);
//		rh.setResponseTag(ResponseTag.IS_COMMAND);
//		rh.setUid("1");
//		rh.setEncryptTag(EncryptTag.AES128_ENCRYPT);
		DataEncoder<VehicleGpsReq> vDataEncoder = new DataEncoder<VehicleGpsReq>();
		byte[] bytes;
		try {
			bytes = vDataEncoder.encode(vlData);
			System.out.println((ByteArrayUtil.toHexString(bytes)));
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//ReportBody<VehicleAllData> vData = new ReportBody<VehicleAllData>(rh, v);
		
	}

}
